package com.ruoyi.recycle.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ruoyi.recycle.domain.BillRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public interface BillRecordMapper extends BaseMapper<BillRecord> {
    @Select("select DATE_FORMAT(create_time,'%Y-%m-%d') as create_time, sum(income) as income,count(order_no) as orderCount from bill_record ${ew.customSqlSegment}")
    List<BillRecord> statisticsByTime(@Param(Constants.WRAPPER) LambdaQueryWrapper<BillRecord> queryWrapper);

    Long selectCountOutIntegral(@Param("clientId") Long clientId, @Param("searchTime") Date searchTime);

    Long selectCountInIntegral(@Param("clientId") Long clientId, @Param("searchTime") Date searchTime);

    List<BillRecord> getBillRecordList(@Param("clientId") Long clientId, @Param("searchTime") Date searchTime);

    List<BillRecord> selectInSalesmanBill(@Param("signTime") String signTime, @Param("salesmanId") Long salesmanId);

    List<BillRecord> selectOutSalesmanBill(@Param("signTime") String signTime, @Param("salesmanId") Long salesmanId);

    @Select("select b.* from bill_record b left join housekeeping_order ho on b.order_no = ho.hk_order_no where ho.merchant_id = ${merchantId}")
    List<BillRecord> getHousekeepingBillRecord(@Param("merchantId") Long merchantId);

    @Select("select sum(income) from bill_record ${ew.customSqlSegment}")
    BigDecimal sumPercentage(@Param(Constants.WRAPPER) LambdaQueryWrapper<BillRecord> wrapper);


}
